package piconode.ext;

import piconode.core.operator.ActivationFunctionWithDerivative;
import piconode.toolbox.Tools;

/*
 * Created on 6 janv. 2005
 * bredeche(at)lri(point)fr
 * 
 */

public class ActivationFunction_HyperbolicTangent extends ActivationFunctionWithDerivative {

	@Override
	public double applyFunction(double __value) // f(x) = tanh(x) [ f(x) ->
	// [-1,1[ ]
	{
		return (Tools.tanh(__value));
	}

	/**
	 * compute the value from derivative of the hyperbolic tangent function.
	 * WARNING: input parameter is f_activation(x) (i.e. tanh(x)), not x before
	 * activation!!! (thanks to this trick, this function is soooo fast to
	 * compute)
	 */
	@Override
	public double applyDerivativeFunction(double __tanhValue) // f'(x) = 1 -
	// f(x)^2
	{
		return (1 - __tanhValue * __tanhValue);
	}
}
